<template>
  <view class="picker-item">
    <view class="label">{{ label }}</view>
    <view class="location">
      <input
        class="location-input"
        :value="modelValue"
        :placeholder="`请选择${label}`"
        @input="(e) => $emit('update:modelValue', e.target.value)"
      />
      <img class="icon" src="/static/map.png" @click="handleLocation" />
    </view>
  </view>
</template>

<script>
export default {
  props: {
    label: {
      type: String,
      default: '',
    },
    modelValue: {
      type: String,
      default: '',
    },
  },

  methods: {
    handleLocation() {
      uni.chooseLocation({
        success: (res) => {
          this.$emit('change', res);
        },
        fail: (err) => {
          console.log(err);
        },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.picker-item {
  padding: 30rpx 34rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #eee;
  color: #666;
  font-size: 32rpx;
  .label {
    flex-shrink: 0;
  }

  .location {
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
    .location-input {
      margin-right: 10rpx;
      flex: 1;
      height: 100%;
      text-align: right;
    }
    .icon {
      width: 50rpx;
      height: 50rpx;
    }
  }
}
</style>
